package com.primeton.whdc.ccms.reportimpl.mqueue.consumer;

import com.primeton.whdc.ccms.reportimpl.entity.CallRecord;
import com.primeton.whdc.ccms.reportimpl.service.IApiCallRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * @author: YunTao.Li
 * @create: 2020-04-02 22:16
 * @description:
 **/
@Component
public class AsyncTask {
    private Logger logger = LoggerFactory.getLogger(AsyncTask.class);

    /**
     * @param record :
     * @return : java.util.concurrent.Future<java.lang.String>
     * @author : YunTao.Li
     * @date : 2020/4/2 2020/4/2
     */
    @Async("taskExecutor")
    public Future<String> insertRecord(CallRecord record, IApiCallRecordService apiCallRecordService) throws Throwable {
        String id = record.getRequestId();

        logger.info("开始异步插入数据 request id :" + id);
        try {

            apiCallRecordService.addAPICallRecord(record);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            throw throwable;
        }
        return new AsyncResult<>("异步插入api调用记录成功");
    }
}
